package top.kindaries.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import top.kindaries.model.User;
import top.kindaries.service.UserService;

/**
 * Created by Administrator on 2017/8/16.
 */
@RestController     //相当于@Controller和@ResponseBody两个注解
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final Logger kind = LoggerFactory.getLogger("kind");

    @RequestMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public Boolean addUser(User user) {
        return userService.addUser(user);
    }

    @RequestMapping(value = "/getUser", produces = {"application/json;charset=UTF-8"})
    public Object getUser(User user) {
        return userService.getUser(user);
    }

    @RequestMapping(value = "/{name}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public User getUserById(@PathVariable("id") String name) {
        return userService.getUserByName(name);
    }

}